<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<script type="text/javascript">

    function createFlv(streamName, streamIp) {
        var entityLiveStream = new EntityManagement();
        entityLiveStream.entityName = "直播流扩展";
        entityLiveStream.entityPath = "/stream/flvStream";
        entityLiveStream.entityTable = "liveStreamTable";
        entityLiveStream.add = function (com, grid) {
            return top.qBox.iFLoad({title:'新增' + entityLiveStream.entityName, src:ctx + entityLiveStream.entityPath + "/input.action?fatherId=${id}&streamName=" + streamName + "&streamIp=" + streamIp, afterHide:entityLiveStream.refresh});
        }
        entityLiveStream.add();
    }
    function createTs(streamName, streamIp) {
        var entityLiveStream = new EntityManagement();
        entityLiveStream.entityName = "直播流扩展";
        entityLiveStream.entityPath = "/stream/tsStream";
        entityLiveStream.entityTable = "liveStreamTable";
        entityLiveStream.add = function (com, grid) {
            return top.qBox.iFLoad({title:'新增' + entityLiveStream.entityName, src:ctx + entityLiveStream.entityPath + "/input.action?fatherId=${id}&streamName=" + streamName + "&streamIp=" + streamIp, afterHide:entityLiveStream.refresh});
        }
        entityLiveStream.add();
    }
    function createP2P(streamName, streamIp) {
        var entityLiveStream = new EntityManagement();
        entityLiveStream.entityName = "直播流扩展";
        entityLiveStream.entityPath = "/stream/p2pStream";
        entityLiveStream.entityTable = "liveStreamTable";
        entityLiveStream.add = function (com, grid) {
            return top.qBox.iFLoad({title:'新增' + entityLiveStream.entityName, src:ctx + entityLiveStream.entityPath + "/input.action?fatherId=${id}&streamName=" + streamName + "&streamIp=" + streamIp, afterHide:entityLiveStream.refresh});
        }
        entityLiveStream.add();
    }
    $(document).ready(function(){
        var entityManagement = new EntityManagement();
        entityManagement.entityName = "直播流";
        entityManagement.entityPath = "/stream/stream";
        entityManagement.entityTable = "streamTable";

        var entityLiveStreamt = new EntityManagement();
        entityLiveStreamt.entityName = "直播流扩展";
        entityLiveStreamt.entityPath = "/stream/liveStream";
        entityLiveStreamt.entityTable = "liveStreamTable";

        entityManagement.add = function (com, grid) {
            return top.qBox.iFLoad({title:'新增' + entityManagement.entityName, src:ctx + entityManagement.entityPath + "/input.action?entity.fatherId=${id}", afterHide:entityManagement.refresh});
        }

        //修改
        entityManagement.edit = function (com, grid) {
            if (BossUtils.checkSingleRecord(com, grid)) {
                row_id = BossUtils.getCurrentRecord(com, grid);
                top.qBox.iFLoad({title:'修改' + entityManagement.entityName, src:ctx + entityManagement.entityPath + "/input.action?id=" + row_id, afterHide:entityManagement.refresh});
            }
        }

        //删除
        entityManagement.del = function (com, grid) {
            if (BossUtils.checkSingleRecord(com, grid)) {
                row_id = BossUtils.getCurrentRecord(com, grid);
                jQuery.ajax({
                    url:ctx + entityManagement.entityPath +  '/delete.action?id=' + row_id + '&t=' + new Date().getTime(),
                    type:"GET",
                    success:function (data) {
                        var ret = eval('(' + data + ')');
                        var message = "删除" + entityManagement.entityName + "<span style='color: red'>" + row_id + "</span>：" + ret.message;
                        top.Boxy.alert(message, null, {title:"提示信息"});

                        if (ret.code == 'A00000') {
                            entityManagement.refresh();
                            entityLiveStreamt.refresh();
                        }
                    }
                })
            }
        }

        $("#"+entityManagement.entityTable).flexigrid({
            url : "/epg-web"+entityManagement.entityPath+'/list.action',
            dataType : 'json',
            height: "auto",
            title:"直播流信息",
            customTitle:false,
            params:[{"name":"fatherId",value:${id}}],
            colModel: [
                {display: 'ID', name : 'id', width : 70, sortable : false, align: 'center', hide : false},
                {display: '直播频道ID', name : 'fatherId', width : 70, sortable : false, align : 'center'},
                {display: '流名称', name : 'streamName', width : 120, sortable : false, align : 'center'},
                {display: 'RTMP地址', name : 'streamIp', width : 70, sortable : false, align : 'center'},
                {display: '清晰度', name : 'streamType', width : 70, sortable : false, align : 'center'},
                {display: '编码状态', name : 'status', width : 70, sortable : false, align : 'center'},
                {display: '是否启用', name : 'isEnable', width : 70, sortable : false, align : 'center'},
                {display: '码流', name : 'bitRate', width : 70, sortable : false, align : 'center'},
                {display: '推流流速率', name : 'inputBits', width : 70, sortable : false, align : 'center'},
                {display: '下载流速率', name : 'outputBits', width : 70, sortable : false, align : 'center'},
                {display: '画面比例', name : 'aspectRatio', width : 70, sortable : false, align : 'center'},
                {display: '画面尺寸', name : 'screenSize', width : 70, sortable : false, align : 'center'},
                {display: '镜像服务器数', name : 'peerCount', width : 70, sortable : false, align : 'center'},
                {display: '添加时间', name : 'addTime', width : 120, sortable : false, align : 'center'},
                {display: '最后更新时间', name : 'updateTime', width : 120, sortable : false, align : 'center'},
                {display: '创建', name : 'create', width : 150, sortable : true, align: 'center'}
            ],
            useRp: false,
            usepager: false,
            buttons: [
                {"name": "新增", bclass: 'add', "onpress": entityManagement.add},
                {separator : true},// 设置分割线
                {"name": "修改", bclass: 'edit', "onpress": entityManagement.edit},
                {separator : true},// 设置分割线
                {"name": "删除", bclass: 'delete', "onpress": entityManagement.del}
            ]
        });
    })

</script>